package com.fantasy.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * 
 * @author heqichang 服务端接收信息线程
 * */
public class ThreadServer extends Thread {

	Socket serverSocket;

	public void run() {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					serverSocket.getInputStream()));
			String read = new String();

			// 接受客户端的姓名信息
			String name = br.readLine();

			// 循环接受客户端信息
			while (true) {
				read = br.readLine();
				System.out.println(name + "说：" + read);

				if (read.equals("bye")) {
					break;
				}
			}

			br.close();
			serverSocket.close();

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ThreadServer(Socket server) {
		serverSocket = server;
	}
}
